<?php

	if ( !isset($_REQUEST["files"]) ) die();
	
	$filesStr = $_REQUEST["files"];
	$files = explode(",", $filesStr);
	
	$totalWidth = 0;
	$totalHeight = 0;
	$imageWidth = 0;
	$imageHeight = 0;
	
	foreach( $files as $file ) {
		$info = getimagesize($file);
		if ( $imageWidth == 0 ) $imageWidth = $info[0];
		if ( $imageHeight == 0 ) $imageHeight = $info[1];
		if ( $totalHeight == 0 ) $totalHeight = $info[1];
		$totalWidth += $info[0];
	}

	$output = ".myIcons {\n\tbackground-image: url('path/to/image');\n\tbackground-repeat: no-repeat;\n\twidth: {$imageWidth}px;\n\theight: {$imageHeight}px;\n\ttext-align: center;\n}\n\n";

	$i = 0;
	foreach( $files as $file ) {
		$pos = ($imageWidth * $i) * -1;
		$split = explode("/", $file);
		$filename = $split[count($split)-1];
		$split = explode(".", $filename);
		$name = ".icon".ucfirst($split[0]);
		$output .= "{$name} { background-position: {$pos}px; }\n";
		$i++;
	}

	$json = array("css" => $output);
	die( json_encode($json) );

?>
